﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Pages_Chitiet : System.Web.UI.Page
{
    private string strMa = string.Empty;
    public string strNhom = string.Empty;
    public string strten = string.Empty;
    public string strMaNhom = string.Empty;
    private Entities en = new Entities();
    private DataAccess da = new DataAccess();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["mahh"] != null && Request.QueryString["mahh"].ToString() != "")
        {
            strMa = Request.QueryString["mahh"].ToString();
        }
        if (!IsPostBack)
        {
            this.GetSanSPinfo(strMa);
            this.GetHangTheoNhom(strMaNhom);
        }
    }

    private void GetSanSPinfo(string strMa)
    {
        SqlDataReader drd;
        SqlCommand comm = new SqlCommand("getHangHoabyMa", da.SqlConn());
        comm.CommandType = CommandType.StoredProcedure;
        comm.Parameters.AddWithValue("@Ma", strMa);
        comm.Connection.Open();
        drd = comm.ExecuteReader();
        if (drd.Read())
        {
            this.txtmasp.Text = drd["MaHang"].ToString();
            this.txttensp.Text = drd["TenHang"].ToString();
            this.txtmota.Text = drd["Mota"].ToString();
            this.txtnhomsp.Text = drd["TenNhomHang"].ToString();
            imgSp.ImageUrl = drd["Images"].ToString();
            this.txtGia.Text = en.fomat(drd["DonGia"].ToString());
            strNhom = drd["TenNhomHang"].ToString();
            this.txtMaNhom.Text = drd["MaNhomHang"].ToString();
            this.strMaNhom = this.txtMaNhom.Text;
        }
        drd.Close();
        drd.Dispose();
        comm.Connection.Close();
        comm.Connection.Dispose();
    }
    protected void GetHangTheoNhom(string sr)
    {
        DataSet dts = new DataSet();
        SqlDataAdapter adt = new SqlDataAdapter();
        SqlCommand comm = new SqlCommand("GetHangByMaNhom", da.SqlConn());
        comm.CommandType = CommandType.StoredProcedure;
        comm.Parameters.AddWithValue("@Ma", sr);
        comm.Connection.Open();
        adt.SelectCommand = comm;
        adt.Fill(dts);
        this.DataList1.DataSource = dts;
        this.DataList1.DataBind();
        dts.Clear();
        adt.Dispose();
        comm.Connection.Close();
        comm.Connection.Dispose();
    }
    protected void LinkAddvaogiohang_Click(object sender, ImageClickEventArgs e)
    {
        string str = wrstatus(txtmasp.Text);
        Response.Redirect(str);
    }
    public string wrstatus(string product_id)
    {
        string sl = "";

        if (this.txtsoluong == null)
        {
            sl = "3";
        }
        else
        {
            sl = this.txtsoluong.Text.ToString();
        }
        string img ="ReturnCart.aspx?id="+ product_id;
        return img.ToString();
    }
}
